package controller.account;

import service.account.AccountService;
import service.account.AccountServiceImpl;
import service.user.UserService;
import service.user.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class AddAccount extends HttpServlet {
    private static final long serialVersionUID = 1L;
    AccountService accountService = new AccountServiceImpl();
    public AddAccount() {
        super();
        // TODO Auto-generated constructor stub
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        String username = request.getParameter("username");
        String info = request.getParameter("info");
        String time = request.getParameter("time");
        float out = 0;
        float come = 0;
        if (request.getParameter("out")!=""||request.getParameter("out")!=null)
            out = Float.parseFloat(request.getParameter("out"));
        if (request.getParameter("come")!=""||request.getParameter("come")!=null)
            come = Float.parseFloat(request.getParameter("come"));
        int i = accountService.addAccount(info,out,come,time,username);
        if (i>0) {

            response.sendRedirect(request.getContextPath() + "/page/user/userAdd.jsp?msg=1");
        } else {
            response.sendRedirect(request.getContextPath() + "/page/user/userAdd.jsp?msg=0");
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
